﻿using Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Web.Http;
using TP_API.Model;

namespace TP_API.Controllers
{
    public class payapiController : ApiController
    {
        // GET: payapi
        [HttpPost]
        public HttpResponseMessage payrule()
        {
            try{
                ResultModel<paylistInfo> result = new ResultModel<paylistInfo>();
                result = JsonConvert.DeserializeObject<ResultModel<paylistInfo>>("{\"status\":1,\"data\":{\"paylist\":[{\"package_id\":\"1\",\"pay_code\":\"365day\",\"pay_name\":\"365\\u5929\\ud83d\\udd25\",\"old_price\":\"288.00\",\"now_price\":\"98.00\",\"pay_gold\":\"0\",\"pay_day\":\"365\",\"is_enable\":\"1\",\"is_delete\":\"0\",\"remark\":\"\",\"create_time\":\"2017-12-27 09:54:31\",\"update_time\":\"2017-12-18 17:35:31\",\"sorting\":\"5\"},{\"package_id\":\"2\",\"pay_code\":\"90day\",\"pay_name\":\"90\\u5929\",\"old_price\":\"80.00\",\"now_price\":\"38.80\",\"pay_gold\":\"0\",\"pay_day\":\"90\",\"is_enable\":\"1\",\"is_delete\":\"0\",\"remark\":\"\",\"create_time\":\"2017-12-18 17:34:29\",\"update_time\":\"2017-12-18 17:34:32\",\"sorting\":\"4\"},{\"package_id\":\"3\",\"pay_code\":\"30day\",\"pay_name\":\"30\\u5929\",\"old_price\":\"30.00\",\"now_price\":\"16.80\",\"pay_gold\":\"0\",\"pay_day\":\"30\",\"is_enable\":\"1\",\"is_delete\":\"0\",\"remark\":\"\",\"create_time\":\"2017-10-31 10:11:03\",\"update_time\":null,\"sorting\":\"3\"},{\"package_id\":\"6\",\"pay_code\":\"500gold\",\"pay_name\":\"500\\u91d1\\u5e01\",\"old_price\":\"35.00\",\"now_price\":\"31.00\",\"pay_gold\":\"500\",\"pay_day\":\"0\",\"is_enable\":\"1\",\"is_delete\":\"0\",\"remark\":\"\",\"create_time\":\"2018-01-26 14:46:42\",\"update_time\":null,\"sorting\":\"3\"},{\"package_id\":\"4\",\"pay_code\":\"200gold\",\"pay_name\":\"200\\u91d1\\u5e01\",\"old_price\":\"18.00\",\"now_price\":\"16.00\",\"pay_gold\":\"200\",\"pay_day\":\"0\",\"is_enable\":\"1\",\"is_delete\":\"0\",\"remark\":\"\",\"create_time\":\"2017-12-30 10:12:38\",\"update_time\":null,\"sorting\":\"2\"}]},\"message\":\"\"}");

                return new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(result), Encoding.UTF8, "application/json"),
                };
            }
            catch (Exception ex)
             {
                return new HttpResponseMessage()
                {
                    Content = new StringContent("", Encoding.UTF8, "application/json"),
                };
            }
        }
        [HttpPost]
        public HttpResponseMessage createorder(createorder_in form)
        {
            try
            {
               string  token = form.token= "cd5b5343a9f8cac5a4dfe80a485ecc4cc74bff94";
                string code = form.code= "365day";
                ResultModel<createorder> result = new ResultModel<createorder>();
                result = JsonConvert.DeserializeObject<ResultModel<createorder>>("{\"status\":1,\"data\":{\"timeStamp\":\"1551431513\",\"nonceStr\":\"pnCK6BFVjP27uHa9\",\"prepayId\":\"wx011711533850173139b433d11775903540\",\"paySign\":\"8E2425F341E4F3F0CB31A649D1FF6CB5\",\"notify_url\":\"http:\\/\\/xbhb.weiku99.cc\\/payapi\\/paycallback\"},\"message\":\"\"}");

                return new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(result), Encoding.UTF8, "application/json"),
                };
            }
            catch (Exception ex)
            {
                return new HttpResponseMessage()
                {
                    Content = new StringContent("", Encoding.UTF8, "application/json"),
                };
            }
        }
        [HttpPost]
        [HttpGet]
        public HttpResponseMessage paycallback()
        {
            try
            {
                ResultModel<createorder> result = new ResultModel<createorder>();
                result = JsonConvert.DeserializeObject<ResultModel<createorder>>("{\"status\":1,\"data\":{\"timeStamp\":\"1551431513\",\"nonceStr\":\"pnCK6BFVjP27uHa9\",\"prepayId\":\"wx011711533850173139b433d11775903540\",\"paySign\":\"8E2425F341E4F3F0CB31A649D1FF6CB5\",\"notify_url\":\"http:\\/\\/xbhb.weiku99.cc\\/payapi\\/paycallback\"},\"message\":\"\"}");

                return new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(result), Encoding.UTF8, "application/json"),
                };
            }
            catch (Exception ex)
            {
                return new HttpResponseMessage()
                {
                    Content = new StringContent("", Encoding.UTF8, "application/json"),
                };
            }
        }
    }
}